﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Presentation.Web.Admin.Areas.Open.Controllers
{
    public class ArticleController : Infrastructure.Crosscutting.NetFramework.Controllers.OpenBaseController
    {
        Application.Admin.Article.IOpenArticleService openArticleService;

        public ArticleController(Application.Admin.Article.IOpenArticleService openArticle)
        {
            if (openArticle == null)
            {
                throw new ArgumentNullException("openArticleService is null");
            }
            openArticleService = openArticle;
        }

        public JsonResult GetOpenActivity()
        {
            var data = openArticleService.GetOpenActivity();
            if (data == null)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetOpenDiscount()
        {
            var data = openArticleService.GetOpenDiscount();
            if (data == null)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetOpenHoliday()
        {
            var data = openArticleService.GetOpenHoliday();
            if (data == null)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        public ViewResult PreView(int id)
        {
            var data = openArticleService.GetOpenArticleContentById(id);
            ViewBag.contents = string.IsNullOrEmpty(data) ? "没有内容" : HttpUtility.HtmlDecode(data);
            return View();
        }
    }
}
